package compiler;

import house.House;

import java.util.ArrayList;

import returnTypes.Status;
import room.RoomArray;
import tester.RoomTester;

public class CreateHouse implements Create{
	public Object ExecutCommand(ArrayList<String> toDo) {
		String houseName=toDo.get(0);
		House returnHouse= null;
		RoomArray roomContainer=new RoomArray();
		RoomTester houseTester=new RoomTester();
		for(int i=0;i<Compiler.allRooms.size();i++)
		{
			for(int j=2;j<toDo.size();j++)
			{
			if (Compiler.allRooms.get(i).getRoomName().equals(toDo.get(j).substring(0, toDo.get(j).length()-1)))
				if (Compiler.allRooms.get(i).getState()==Status.FREE){
					roomContainer.addRoom(Compiler.allRooms.get(i));
						}	
			}
		}
		for(int i=0;i<roomContainer.getSize();i++)
		{
			roomContainer.getRoom(i).printRoom();
			houseTester.createRoom(roomContainer.getRoom(i).getWalls(), roomContainer.getRoom(i).getThisRoomID());
		}
		returnHouse=new House(roomContainer,houseTester);
		returnHouse.setName(houseName);
		returnHouse.setState(Status.LOCKED);
		return returnHouse;
	}
}
